//
//  NT_QuestionnaireView.m
//  YHNote
//
//  Created by 赵凯元 on 2019/6/25.
//  Copyright © 2019 xingchen. All rights reserved.
//

#import "NT_QuestionnaireView.h"

@implementation NT_QuestionnaireView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpView];
    }
    return self;
}

- (void)setUpView {
    
    self.textView = ({
        UITextView *view = [[UITextView alloc]init];
        view.textColor = RGB(60, 60, 60);
        view.font = FontPFRegular(kRelativeWidth(14));
        view.delegate = self;
        [self addSubview:view];
        view;
    });
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRelativeHeight(20));
        make.left.mas_offset(kRelativeWidth(10));
        make.right.mas_offset(-kRelativeWidth(10));
        make.height.mas_equalTo(kRelativeHeight(160));
    }];
    
    self.placehLabel = ({
        UILabel *label = [[UILabel alloc]init];
        label.textColor = rgba(187, 187, 187, 1);
        label.font = FontPFRegular(kRelativeWidth(14));
        label.text = @"Record the mood at the moment...";
        [_textView addSubview:label];
        label;
    });
    [self.placehLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(kRelativeHeight(10));
        make.left.mas_equalTo(kRelativeHeight(5));
        make.right.mas_offset(-kRelativeWidth(10));
        make.height.mas_equalTo(kRelativeHeight(20));
    }];
    
    self.phoneTextField = ({
        UITextField *view = [[UITextField alloc]init];
        view.textColor = [UIColor blackColor];
        view.font = FontPFRegular(kRelativeWidth(16));
        view.borderStyle = UITextBorderStyleLine;
        view.placeholder = @"Please enter contact information";
        [self addSubview:view];
        view;
    });
    [self.phoneTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.textView.mas_bottom).offset(kRelativeHeight(20));
        make.left.mas_equalTo(kRelativeHeight(10));
        make.right.mas_offset(-kRelativeWidth(10));
        make.height.mas_equalTo(kRelativeHeight(40));
    }];
    
    self.QQNumTextField = ({
        UITextField *view = [[UITextField alloc]init];
        view.textColor = [UIColor blackColor];
        view.font = FontPFRegular(kRelativeWidth(16));
        view.borderStyle = UITextBorderStyleLine;
        view.placeholder = @"Please enter the QQ";
        [self addSubview:view];
        view;
    });
    [self.QQNumTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.phoneTextField.mas_bottom).offset(kRelativeHeight(20));
        make.left.mas_equalTo(kRelativeHeight(10));
        make.right.mas_offset(-kRelativeWidth(10));
        make.height.mas_equalTo(kRelativeHeight(40));
    }];
    self.addressTextField =  ({
        UITextField *view = [[UITextField alloc]init];
        view.textColor = [UIColor blackColor];
        view.font = FontPFRegular(kRelativeWidth(16));
        view.borderStyle = UITextBorderStyleLine;
        view.placeholder = @"Please enter address";
        [self addSubview:view];
        view;
    });
    [self.addressTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.QQNumTextField.mas_bottom).offset(kRelativeHeight(20));
        make.left.mas_equalTo(kRelativeHeight(10));
        make.right.mas_offset(-kRelativeWidth(10));
        make.height.mas_equalTo(kRelativeHeight(40));
    }];
    
}
#pragma mark===============
-(void)textViewDidChange:(UITextView *)textView{
    //清空内容
    _placehLabel.text = @"";
    if (_textView.text.length == 0) {
        _placehLabel.text = @"Record the mood at the moment...";
    }
    if ([textView.text length] > 200) {
        textView.text = [textView.text substringWithRange:NSMakeRange(0, 200)];
        [textView.undoManager removeAllActions];
        [textView becomeFirstResponder];
        return;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
